package com.match.servicebase.exceptionhandler;

import com.match.commonutils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 芊薰
 */
//@ControllerAdvice
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler(IllegalArgumentException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ResponseBody
    public Result error(IllegalArgumentException e){
        log.error("Assert异常:-----------------------{}",e.getMessage());
        return Result.error().message(e.getMessage());
    }


    @ExceptionHandler(RuntimeException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ResponseBody
    public Result error(RuntimeException e) {
        log.error("Runtime异常:-----------------------{}",e.getMessage());
        return Result.error().message(e.getMessage());
    }


    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result error(ArithmeticException e) {
        e.printStackTrace();
        return Result.error().message("执行了ArithmeticException异常处理..");
    }


    @ExceptionHandler(com.match.servicebase.exceptionhandler.AdiosException.class)
    @ResponseBody
    public Result error(com.match.servicebase.exceptionhandler.AdiosException e) {
        log.error(e.getMessage());
        e.printStackTrace();

        return Result.error().code(e.getCode()).message(e.getMsg());
    }

}
